package blue.mqtt4j.client;

/**
 * @author Jin Zheng
 * @since 1.0 2020-10-16
 */
public class LoggerConsumerListener implements ConsumerListener
{
	public LoggerConsumerListener()
	{
	}

	@Override
	public void onReceived(MqttMessage message)
	{
		String payload = null;
		String type = null;
		if (message.payload() instanceof byte[])
		{
			type = "byte[]";
			payload = new String((byte[]) message.payload());
		}
		else if (message.payload() instanceof CharSequence)
		{
			type = "String";
			payload = ((CharSequence) message.payload()).toString();
		}
		else
		{
			type = "Object";
			payload = message.payload().toString();
		}
		System.out.printf("topic: %s, qos: %s, payload(%s): %s\n", message.topic(), message.qos(), type, payload);
	}
}
